package com.example.dingtalklogin.manager.dingtalk;

import com.example.dingtalklogin.common.util.SpringUtil;
import feign.RequestInterceptor;
import feign.RequestTemplate;

import java.util.Collection;

public class ApiTokenInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        Collection<String> tokenHeaders = requestTemplate.headers().get("x-acs-dingtalk-access-token");
        // 当token没有传入的时候才会添加，照顾到某些接口需要用户token
        if(!(tokenHeaders != null && tokenHeaders.size() > 0)){
            AccessTokenManager accessTokenManager = SpringUtil.getBean(AccessTokenManager.class);
            requestTemplate.header("x-acs-dingtalk-access-token", accessTokenManager.getToken());
        }
    }
}
